/// @tags: Base Circle
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

namespace BlueQuantum {

typedef long long ll;

int const N = 5e4 + 5, M = 1e5 + 5, BIT = 64;

struct Edge {
  int v, nxt;
  ll w;
} e[M << 1];

int e_cnt, heads[N];
bool vis[N];
ll num[BIT], dis[N];

inline void add(int u, int v, ll w) {
  e[++e_cnt].v = v, e[e_cnt].nxt = heads[u], heads[u] = e_cnt, e[e_cnt].w = w;
}

inline void insert(ll x) {
  for (int i = BIT - 1; i >= 0; --i)
    if ((x >> i) & 1) {
      if (!num[i]) return num[i] = x, void();
      x ^= num[i];
    }
}

inline ll query(ll x) {
  ll res = x;
  for (int i = BIT - 1; i >= 0; i--)
    if ((res ^ num[i]) > res) res ^= num[i];
  return res;
}

void dfs(int u, ll res) {
  dis[u] = res, vis[u] = true;
  for (int i = heads[u]; i; i = e[i].nxt)
    if (!vis[e[i].v]) dfs(e[i].v, res ^ e[i].w);
    else
      insert(res ^ e[i].w ^ dis[e[i].v]);
}

inline int main() {
  int n, m;
  cin >> n >> m;
  ll c;
  for (int i = 1, a, b; i <= m; i++) cin >> a >> b >> c, add(a, b, c), add(b, a, c);
  dfs(1, 0);
  cout << query(dis[n]);
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("P4151 [WC2011] 最大XOR和路径.in", "r", stdin);
  freopen("P4151 [WC2011] 最大XOR和路径.out", "w", stdout);
#endif
#endif

  ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
